package business.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import model.TDuty;
import business.basic.iHibBaseDAO;
import business.basic.iHibBaseDAOImpl;
import business.dao.DutyDAO;

@Component("dutydao")
public class DutyDAOImpl implements DutyDAO {
	
	private iHibBaseDAO bdao = null;
	
	public DutyDAOImpl(){
		bdao = new iHibBaseDAOImpl();
	}
	
	public void setBdao(iHibBaseDAO bdao) {
		this.bdao = bdao;
	}

	@Override
	public int add(TDuty duty) {
		Object obj = bdao.insert(duty);
		if (obj!=null) {
			return Integer.parseInt(obj.toString());
		}
		return 0;
	}

	@Override
	public boolean update(TDuty duty) {
		return bdao.update(duty);
	}

	@Override
	public boolean delete(int dutyid) {
		return bdao.delete(TDuty.class, dutyid);
	}

	@Override
	public TDuty getTDutyId(int dutyid) {
		return (TDuty)bdao.findById(TDuty.class, dutyid);
	}

	@Override
	public List<TDuty> getTDuty() {
		String hql = "from TDuty";
		return bdao.select(hql);
	}

	@Override
	public List<TDuty> getTDutyByWhere(String wherecondition, int startPage,
			int pageSize) {
		String hql = "from TDuty";
		if (wherecondition!=null && !wherecondition.equals("")) {
			hql +=wherecondition;
		}
		return bdao.selectByPage(hql, startPage, pageSize);
	}

	@Override
	public int getAmounTDutyByWhere(String wherecondition) {
		String hql = "select count(*) from TDuty";
		if (wherecondition!=null && !wherecondition.equals("")) {
			hql +=wherecondition;
		}
		return bdao.selectValue(hql);
	}

}
